package com.by.springboottwodatabases.controller;

import com.by.springboottwodatabases.controller.request.TestRequestBean;
import com.by.springboottwodatabases.controller.request.TwoRequestBean;
import com.by.springboottwodatabases.domain.two.DTestTwo;
import com.by.springboottwodatabases.domain.two.DTwo;
import com.by.springboottwodatabases.service.TwoService;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(value = "/two")
public class TwoController {

    private final TwoService twoService;

    public TwoController(TwoService twoService) {
        this.twoService = twoService;
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    public DTwo createTwo(@RequestBody TwoRequestBean bean, HttpServletRequest request) {
        return twoService.createTwo(bean);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public DTwo getTwo(@PathVariable Long id, HttpServletRequest request) {
        return twoService.findById(id);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
    public DTwo updateTwo(@PathVariable Long id, @RequestBody TwoRequestBean bean, HttpServletRequest request) {
        return twoService.updateTwo(id, bean);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public void deleteOne(@PathVariable Long id, HttpServletRequest request) {
        twoService.deleteTwo(id);
    }


    @RequestMapping(value = "/test", method = RequestMethod.POST)
    public DTestTwo createTest(@RequestBody TestRequestBean bean, HttpServletRequest request) {
        return twoService.createTest(bean);
    }

    @RequestMapping(value = "/test/{id}", method = RequestMethod.GET)
    public DTestTwo getTest(@PathVariable Long id, HttpServletRequest request) {
        return twoService.findTestById(id);
    }

    @RequestMapping(value = "/test/{id}", method = RequestMethod.PUT)
    public DTestTwo updateTest(@PathVariable Long id, @RequestBody TestRequestBean bean, HttpServletRequest request) {
        return twoService.updateTest(id, bean);
    }

    @RequestMapping(value = "/test/{id}", method = RequestMethod.DELETE)
    public void deleteTest(@PathVariable Long id, HttpServletRequest request) {
        twoService.deleteTest(id);
    }

}
